﻿using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.EntityFrameworkCore;
using Wpf.Ui.Controls;

using WpfApp1.Helpers;
using WpfApp1.Models;
using WpfApp1.ViewModels;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : FluentWindow
    {
        public MainWindowViewModel ViewModel { get; }

        private MainWindowViewModel Mm => (MainWindowViewModel)DataContext;

        private readonly CodeContext cc = new();

        private readonly CollectionViewSource CodesViewSource;
        private readonly CollectionViewSource CodesTreeViewSource;

        public MainWindow()
        {
            InitializeComponent();
            //CodesViewSource = (CollectionViewSource)FindResource(nameof(CodesViewSource));
            //CodesTreeViewSource = (CollectionViewSource)FindResource(nameof(CodesTreeViewSource));

            // this is for demo purposes only, to make it easier
            // to get up and running
            cc.Database.EnsureCreated();

            // load the entities into EF Core
            cc.Codes.Load();
            //Mm.CodeNodes = cc.Codes.Local.ToObservableCollection();
            // bind to the source
            //CodesViewSource.Source = Mm.CodeNodes;
            //CodesTreeViewSource.Source = Mm.CodeNodes.GetTrees();

            //InitTreeNodes();
        }

        #region TreeView的Binding相关

        //TreeView绑定的TreeNodes
        //private ObservableCollection<TreeNode> _TreeNodes;

        //{
        //    get { return _TreeNodes; }
        //    set { SetProperty(ref _TreeNodes, value); }
        //}
        /// <summary>
        /// 初始化Tree
        /// </summary>
        //public void InitTreeNodes()
        //{
        //    //  TreeNodes = new UtilTreeNode().GetTrees();      //将TreeNodes之间的关系绑定
        //}

        #endregion TreeView的Binding相关

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }
    }
}